package com.github.wendao76.test.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * 线程B
 *
 * @author wendao76
 * @version 1.0
 * @since 2022-2-5
 */
public class ThreadClsB extends Thread {
  CyclicBarrier cyclicBarrier;
  private int num;

  public ThreadClsB(int num, CyclicBarrier cyclicBarrier) {
    this.setName("ThreadB");
    this.num = num;
    this.cyclicBarrier = cyclicBarrier;
  }

  @Override
  public void run() {
    try {
      System.out.println(this.getName() + ":" + this.num);
      cyclicBarrier.await();
      System.out.println("over:" + this.num);
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (BrokenBarrierException e) {
      e.printStackTrace();
    }
    super.run();
  }
}
